# -*- coding: utf-8 -*-
# @Time : 2019/1/18 11:51
# @Author : Administrator
# @File : stu_mana.py
# @Project : code
# @title : 学员管理-今日考勤、阶段测评
from boss_GUI.common.login_dec import LoDec
import time
from selenium.webdriver.support.ui import Select


class StuManage():
    def __init__(self):
        self.driver = LoDec().dec("wncd005", "woniu123", "woniu123")  # 解密

    def click_c(self):   #进入今日考勤模块
        time.sleep(0.5)
        self.driver.find_element_by_link_text('学员管理').click()
        self.driver.find_element_by_link_text('今日考勤').click()
        time.sleep(0.5)

    def click_a(self):    #进入今日测评模块
        time.sleep(2)
        self.driver.find_element_by_link_text('学员管理').click()
        self.driver.find_element_by_link_text('阶段测评').click()
        self.driver.find_element_by_xpath('//*[@id="examination"]/div[1]/button').click()

    def clocking_in(self,a):    #今日考勤，对单个学生进行考勤操作
        self.click_c()
        # self.driver.find_element_by_xpath('//*[@id="attendance_table"]/tbody/tr[1]/td[7]/select').send_keys(a)
        Select(self.driver.find_element_by_xpath('/html/body/div[7]/div[3]/div/div/div[2]/div[2]/div[2]/div[2]/table/tbody/tr[1]/td[7]/select')).select_by_visible_text(a)
        self.driver.find_element_by_xpath('//*[@id="confirmAttenBtn_1252"]').click()
        time.sleep(1)
        ac = self.driver.find_element_by_xpath('/html/body/div[7]/div[3]/div/div/div[2]/div[2]/div[2]/div[2]/table/tbody/tr[1]/td[6]').text
        # return ac
        print(ac)
    def clo_query(self):    #姓名输入学生姓名，列表展示该学生的信息
        self.click_c()
        # 取第一行的学生姓名，进行查询
        name = self.driver.find_element_by_xpath('//*[@id="attendance_table"]/tbody/tr/td[1]').text
        self.driver.find_element_by_xpath('//*[@id="atten"]/div[1]/input').send_keys(name)
        self.driver.find_element_by_xpath('//*[@id="atten"]/div[1]/button[1]').click()
        time.sleep(2)
        result = self.driver.find_element_by_xpath('//*[@id="attendance_table"]/tbody/tr/td[1]').text
        return name,result

    def batch_clo(self,a):   #批量考勤,对单个学生进行考勤操作
        self.click_c()
        time.sleep(2)
        self.driver.find_element_by_xpath('//*[@id="attendance_table"]/tbody/tr/td[7]/select').send_keys(a)
        self.driver.find_element_by_xpath('//*[@id="atten"]/div[1]/button[2]').click()
        time.sleep(2)
        self.driver.find_element_by_xpath('/html/body/div[18]/div/div/div[3]/button[2]'). click()
        time.sleep(2)
        self.driver.find_element_by_xpath('/html/body/div[18]/div/div/div[3]/button').click()
        time.sleep(1)
        ac = self.driver.find_element_by_xpath('//*[@id="attendance_table"]/tbody/tr/td[6]').text
        return ac

    def ass_query(self):   #姓名框输入第一行的姓名，进行查询
        self.click_a()
        time.sleep(2)
        #取第一行的姓名，进行查询
        name = self.driver.find_element_by_xpath('//*[@id="exam-table"]/tbody/tr[1]/td[1]').text
        self.driver.find_element_by_xpath('//*[@id="examination"]/div[1]/input').send_keys(name)
        self.driver.find_element_by_xpath('//*[@id="examination"]/div[1]/button').click()
        ac = self.driver.find_element_by_xpath('//*[@id="exam-table"]/tbody/tr[1]/td[1]').text
        return name,ac

    def ass_exe(self,sec,score,content):    #对第一行的学生进行测评
        self.click_a()
        time.sleep(2)
        self.driver.find_element_by_xpath('//*[@id="exam-table"]/tbody/tr[1]/td[6]/button[1]').click()
        self.driver.find_element_by_xpath('//*[@id="score-form"]/div/div[2]/div[1]/select').send_keys(sec)
        self.driver.find_element_by_xpath('//*[@id="score-form"]/div/div[2]/div[2]/input').send_keys(score)
        self.driver.find_element_by_xpath('//*[@id="score-form"]/div/div[3]/textarea').send_keys(content)
        self.driver.find_element_by_id("saveStageBtn").click()

    def ass_down(self,dir,cla):    #对第一行的学生进行降级操作
        self.click_a()
        time.sleep(2)
        name = self.driver.find_element_by_xpath('//*[@id="exam-table"]/tbody/tr[1]/td[1]').text
        self.driver.find_element_by_xpath('//*[@id="exam-table"]/tbody/tr[1]/td[6]/button[2]').click()
        self.driver.find_element_by_xpath('//*[@id="repeat-form"]/div/div[2]/div[2]/select').send_keys(dir)
        # self.driver.find_element_by_xpath('/html/body/div[11]/div/div/div[2]/form/div/div[2]/div[3]/select').send_keys(cla)
        Select(self.driver.find_element_by_xpath('/html/body/div[11]/div/div/div[2]/form/div/div[2]/div[3]/select')).select_by_visible_text(cla)
        self.driver.find_element_by_xpath('//*[@id="saveRepeatBtn"]').click()
        self.driver.find_element_by_xpath('//*[@id="examination"]/div[1]/input').send_keys(name)
        self.driver.find_element_by_xpath('//*[@id="examination"]/div[1]/button').click()
        cla_ac = self.driver.find_element_by_xpath('//*[@id="exam-table"]/tbody/tr/td[3]').text
        dir_ac = self.driver.find_element_by_xpath('//*[@id="exam-table"]/tbody/tr/td[4]').text
        return cla_ac,dir_ac

if __name__ == '__main__':
    # re = StuManage().ass_down("测试","WNCDC032")
    re = StuManage()
    re.clocking_in("旷课")
